<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="C" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.wmm.service.ClassesService" %>
<%@ page import="com.wmm.bean.PageBean" %>
<%@ page import="com.wmm.bean.Classes" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: Sakura
  Date: 2020/10/26
  Time: 15:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <script src="js/bootstrap.min.js"></script>
    <meta charset="utf-8">
    <title>班级管理界面</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script>

        function check() {
            var flag = confirm("确定删除这条记录吗？");

            if (flag) {
                return true;

            } else {
                return false;
            }
        }

        function fun1() {
            var classNo = $("#number11").val();
            var className = $("#name11").val();
            $("#a1").attr("href", "queryClass?classNo=" + classNo + "&className=" + className);
        }

        function deleteAll() {

            if (isSelected()) {
                if (confirm("确定删除选中的数据吗？")) {
                    var params = [];
                    var del = document.getElementsByTagName("input");
                    for (var i = 0; i < del.length; i++) {
                        if (del[i].name != "delAll") {
                            if (del[i].checked) {
                                del[i].name = "check";
                                params[params.length++] = del[i].value;
                            }
                        }
                    }
                    window.location = "deleteAllClass?params=" + params;
                }
            } else {
                alert("请至少选择一条要删除的数据！")
            }

        }

        //判断是否有数据被选中
        function isSelected() {
            var isFlag = false;
            var del = document.getElementsByTagName("input");
            for (var i = 0; i < del.length; i++) {
                if (del[i].name == "delAll") {

                    isFlag = false;
                } else {
                    if (del[i].checked) {
                        isFlag = true;
                    }
                }
            }
            return isFlag;
        }

        //点击最上面的按钮实现下方选择框的反向勾选
        function delFun() {

            var del = document.getElementsByTagName("input");
            for (var i = 0; i < del.length; i++) {
                if (del[i].name != "delAll") {
                    del[i].checked = !del[i].checked;
                }
            }


        }


        function selectPage() {
            var numbers = $("#number11").val();
            var name11 = $("#name11").val();
            var href = $(this).getAttribute("href");
            alert(href);
        }
    </script>
<body style="background-color: lightskyblue">
<div align="center" style="font-size: 16px;height:68px;vertical-align: center;">

    <br/>
    <a href = "findStudentByPage" class="btn-success" style="width: 66px;height:60px;">进入学生管理界面</a>&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a href = "findClassByPage" class="btn-success">进入班级管理界面</a>&nbsp;/&nbsp;&nbsp;&nbsp;
</div>
<div style="border: 1px solid red;height: 120px;font-size: 30px;align-items: center;">
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>
    <a href="addClass.jsp" target="_self" class="btn btn-success">增加班级</a>

    <input type="text" placeholder="按照班级编号查询" name="classNo" id="number11"
           style="font-size:25px;background-color: lightgray;width:180px;" >
    <input type="text" placeholder="按照班级名称查询" name="className" id="name11"
           style="background-color: lightgray;font-size:25px;width:220px;" >
    <a href="queryClass" target="_self" onclick="fun1()" id="a1" class="btn btn-success">查询</a>

</div>
<br/>
<br/>
<br/>

<table width="100%" border="3px solid green" cellspacing="0px" cellpadding="0px" class="table table-hover table-striped">
    <caption style="text-align: center; font-size: larger;" >学生信息显示</caption>
    <tr>
        <th><input type="button" id="delAll" name="delAll" onclick="delFun()" value="反选"/></th>
        <th>班级编号</th>
        <th>班级名称</th>
        <th>年级</th>
        <th>班主任</th>
        <th>班级口号</th>
        <th>班级人数</th>
        <th>操作</th>
    </tr>

    <%
        PageBean<Classes> pageBean = ((PageBean<Classes>)session.getAttribute("queryClassList"));
        List<Classes> list = (List<Classes>) pageBean.getList();
        pageContext.setAttribute("pageBean",pageBean);
        pageContext.setAttribute("list",list);
    %>
    <C:forEach var="st" items="${list}">
    <tr>
        <td><input type="checkbox" id="${st.getClassNo()},${st.getClassName()}"  value="${st.getClassNo()},${st.getClassName()}"/></td>
        <td><c:out value="${st.getClassNo()}"></c:out>
        </td>
        <td><c:out value="${st.getClassName()}"></c:out>
        </td>
        <td><c:out value="${st.getGrade()}"></c:out>
        </td>
        <td><c:out value="${st.getClassTeacher()}"></c:out>
        </td>
        <td><c:out value="${st.getClassSlogan()}"></c:out>
        </td>
        <td><c:out value="${st.getClassNumber()}"></c:out>
        </td>

        <td><a href="updateClass?classNo=<c:out value="${st.getClassNo()}"></c:out>&className=<c:out value="${st.getClassName()}"></c:out>">修改</a> &nbsp;&nbsp;
            <a href="deleteClass?classNo=<c:out value="${st.getClassNo()}"></c:out>&classNumber=<c:out value="${st.getClassNumber()}"></c:out>" onclick="return check()">删除</a>
        </td>
    </tr>
    </C:forEach>
</table>

<br/>
<div align="center">

    <p style="color: cornflowerblue;">一共有<c:out value="${pageBean.getTotalCount()}"></c:out>条记录，每页分成了<c:out value="${pageBean.getRows()}"></c:out>条记录,
        当前第<c:out value="${pageBean.getCurrentPage()}"></c:out>页,一共有<c:out value="${pageBean.getTotalPage()}"></c:out>页</p>
    <ul class="pagination" style="align-content: center">
        <li><a href="#">&laquo;</a></li>
        <%
            for(int i = 1;i <= pageBean.getTotalPage();i++) {

                if(i == pageBean.getCurrentPage()){
        %>
        <li style="background-color: darkgrey;"><a href="findClassByPage?currentPage=<%=i%>&rows=5" onclick="selectPage()"><%=i%></a></li>

        <%
            }else {
        %>
        <li><a href="findClassByPage?currentPage=<%=i%>&rows=5" onclick="selectPage()"><%=i%></a></li>
        <%
                }
            }
        %>
        <li><a href="#">&raquo;</a></li>
    </ul>
</div>

</body>
</html>
